﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RTGS.Library.DataAccess.Rtgs;
using RTGS.Library.Entities.Rtgs;
using System.Configuration;

public partial class page_followup_outgoing_repairlist : System.Web.UI.Page
{
    private stpRecordDetailORepo stpRecordDetailORepo = new stpRecordDetailORepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //TRN
            // Using LINQ to query the collection and group them by the email address
            List<stpRecordDetailO> listTrn = stpRecordDetailORepo.GetList();
            var trn = from p in listTrn
                      orderby p.recordDetailOtrTrn
                              group p by p.recordDetailOtrTrn into g
                              select new {  Trn = g.Key, Accounts = g };

            // Output the email address and the count of records for each group
            foreach (var item in trn)
            {
                ddlTrn.Items.Add(new ListItem(item.Trn, item.Trn));
            }

            ddlTrn.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));

            
            //Batch Reff
            var batchRef = from batch in listTrn
                           orderby batch.recordDetailOrecordOhBatchreference
                           group batch by batch.recordDetailOrecordOhBatchreference into gbatch
                           select new { Batch = gbatch.Key, Accounts = gbatch }
                           ;

            // Output the email address and the count of records for each group
            foreach (var itembatch in batchRef)
            {
                ddlBatchRef.Items.Add(new ListItem(itembatch.Batch, itembatch.Batch));
            }

            ddlBatchRef.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));


            //ReffNo
            var refNo = from refno in listTrn
                        orderby refno.recordDetailOrecordRefno
                        group refno by refno.recordDetailOrecordRefno into grefno
                        select new { RefNo = grefno.Key, Accounts = grefno }
                           ;

            // Output the email address and the count of records for each group
            foreach (var itemreff in refNo)
            {
                ddlRefNo.Items.Add(new ListItem(itemreff.RefNo, itemreff.RefNo));
            }

            ddlRefNo.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));

            //VALUE DATE
            var valueDate = from valuedate in listTrn
                            orderby valuedate.recordDetailOtrValuedate
                            group valuedate by valuedate.recordDetailOtrValuedate into gvaluedate
                            select new { ValueDate = gvaluedate.Key, Accounts = gvaluedate }
                           ;

            // Output the email address and the count of records for each group
            foreach (var itemvalue in valueDate)
            {
                ddlValueDate.Items.Add(new ListItem(itemvalue.ValueDate, itemvalue.ValueDate));
            }

            ddlValueDate.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));

            //TO MEMBER
            var toMember = from tomember in listTrn
                           orderby tomember.recordDetailOtrTomember
                           group tomember by tomember.recordDetailOtrTomember into gtomember
                           select new { ToMember = gtomember.Key, Accounts = gtomember }
                           ;

            // Output the email address and the count of records for each group
            foreach (var itemtomember in toMember)
            {
                ddlToMember.Items.Add(new ListItem(itemtomember.ToMember, itemtomember.ToMember));
            }

            ddlToMember.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));


            //STATUS
            var Status = from status in listTrn
                         orderby status.recordDetailOrecordStatus
                         group status by status.recordDetailOrecordStatus into gstatus
                         select new { statusRecord = gstatus.Key, Accounts = gstatus }
                           ;

            // Output the email address and the count of records for each group
            foreach (var itemstatus in Status)
            {
                ddlStatus.Items.Add(new ListItem(itemstatus.statusRecord, itemstatus.statusRecord));
            }

            ddlStatus.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));



        }
    }
}